/**
 * @author Tendo
 * @date 2021/7/15
 * @param {string} s
 * @return {string}
 * @desc 双指针
 */

const reverseWords = s => {
    const ret = []
    let i = 0
    while (i < s.length) {
        let start = i
        while (i < s.length && s.charAt(i) != ' ') {
            i++
        }
        for (let p = start; p < i; p++) {
           ret.push(s.charAt(start + i - 1 - p)) 
        }
        while (i < s.length && s.charAt(i) == ' ') {
            i++
            ret.push(' ')
        }
    }
    return ret.join('')
}